package br.com.trumah.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.trumah.dao.interfaces.AtentendeDAO;
import br.com.trumah.model.AssistenteSocial;
import br.com.trumah.model.Atendente;
import br.com.trumah.utils.HibernateUtil;

public class AtendenteDAOImpl implements AtentendeDAO{

	@Override
	public void salvar(Atendente atendente) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.save(atendente);
		t.commit();
	}

	@Override
	public Atendente obterAtendente(long id) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (Atendente) session.load(Atendente.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Atendente> listar() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		List<Atendente> lista = session.createQuery("from Atendente").list();
		t.commit();
		return lista;
	}

	@Override
	public void remover(Atendente atendente) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.delete(atendente);
		t.commit();
	}

	@Override
	public void atualizar(Atendente atendente) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.update(atendente);
		t.commit();
	}
}
